suppressMessages(library(tidyverse))
suppressMessages(library(magrittr))
library(arrow)

ds <- str_c(c("/Pub/Users/yanhx/database/"), c("epiGAD", "Finngen", "GWAS_Catalog", "IEU", "Pheweb"))
files <- list.files(ds, pattern = "\\.RDS$", recursive = T, full.names = T)

change_file_format <- \(single_file){
  print(cli::cli_h2(dirname(single_file)))
  tmp_file <- readRDS(single_file)
  arrow::write_feather(tmp_file, str_replace(single_file, "RDS$", "feather"))
}

library(furrr)
future::plan(multicore, workers = 4)
furrr::future_walk(files, change_file_format)

plan(sequential)





fs <- list.files("/Pub/Users/wangyk/project/Poroject/F231123001_LUNG_sc_TRM/src_cp", recursive = T, full.names = T)

file_new <- fs %>% map(~ {
    read_lines(.x) -> file
    file <- file[!str_starts(file, "#")]
    file <- file[!{
        file == ""
    }]
})

fs %>%
    str_replace("src_cp", "src_cp2") %>%
    dirname() %>%
    walk(~ dir.create(.x, recursive = T))


walk2(file_new, fs %>%
    str_replace("src_cp", "src_cp2"), ~ write_lines(.x, .y))

styler::style_dir("/Pub/Users/wangyk/project/Poroject/F231123001_LUNG_sc_TRM/src_cp2")
